﻿
/*!
// A part of "Nana Script Utilities", accept the license at http://nana.codeplex.com/license before use it in your own products.
// 这是《Nana脚本工具箱》的一部分，在您自己的产品中使用以前先接受这个使用许可：http://nana.codeplex.com/license
*/
!function(){
var G=this,undefined;
function parseNS(ns){
var a=(ns+"").split("."),b=[];
var i,o=G;
while(i=a.shift()){
b.push(i);
o=o[i]||(o[i]=[b.join(".")]);
}
return o;
}
function requireNS(ns){
return this.loadScript(this.libBase+ns+this.libSuffix);
}
function getXHR(){
try{
return new XMLHttpRequest;
}catch(ex){
try{
return new ActiveXObject("MSXML2.XMLHTTP.6.0");
}catch(ex){
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
}
};
function xhr4loadScript(){
if(this.readyState==4&&this.status==200){
new Function(this.responseText)();
}
}
function loadScript(src,async){
var xhr=getXHR();
xhr.onreadystatechange=xhr4loadScript;
xhr.open("GET",src,async);
xhr.send(null);
}
var Nana=parseNS("Nana");
parseNS("Nana.Json");
parseNS("Nana.Dummy");
Nana.parseNS=parseNS;
Nana.requireNS=requireNS;
Nana.XHR=getXHR;
Nana.loadScript=loadScript;
Nana.libBase=this.$nanaLibBase||"";
Nana.libSuffix=this.$nanaLibSuffix||".js";
function canConstruct(o,c){
var ic;
return(o instanceof c)||(
(ic=o.constructor)&&(
(ic==c)||(
((ic=ic.prototype)!=o)&&canConstruct(ic,c)
)
)
);
}
Function.canConstruct=canConstruct;
Object.prototype.constructBy=function(constructor){
return canConstruct(this,constructor);
};
Function.prototype.canConstruct=function(object){
return canConstruct(object,this);
};
function formalInstance(c){
var a=[],w=function(){};
for(var i=formalInstance.length;i<arguments.length;i++)
a.push("arguments["+i+"]");
w.prototype=eval("new c("+a+")");
return new w;
}
Function.formalInstance=formalInstance;
function newFormal(){
var a=[],w=function(){};
for(var i=0;i<arguments.length;i++)
a.push("arguments["+i+"]");
w.prototype=eval("new this("+a+")");
return new w;
}
Function.prototype.newFormal=newFormal;
var classExtend=new Function("__cc","__nf","return "+function(base,constructor,proto){
if(!proto)proto=new base;
constructor=eval(constructor.toString().replace(/^function(\s.*?)?(\([^)]*\)\s*\{)/,"0,function $2 if(!__cc(this, constructor)) return __nf.apply(constructor, arguments);\n"+
"var __this = this;\n"+
"function inherit(){ base.apply(__this, arguments); }\n"));
constructor.prototype=proto;
return constructor;
})(canConstruct,newFormal);
Function.classExtend=classExtend;
Function.prototype.extend=function(code,proto){
return classExtend(this,code,proto);
};
var constructorHeader=Function.constructorHeader=function(){
var __this=this,constructor=arguments.callee,base=constructor.base;
if(!constructor.canConstruct(this))return constructor.newFormal.apply(constructor,arguments);
function inherit(){
base.apply(__this,arguments);
}
}.toString().match(/\{([\s\S]+)\}/)[1];
function Object7(){
if(!Object7.canConstruct(this))
return formalInstance(Object7);
var self=this;
var protectedRoot={};
function $getProtectedRoot(){
var caller=$getProtectedRoot.caller;
if(caller&&self instanceof caller)
return protectedRoot;
};
this.$getProtectedRoot=$getProtectedRoot;
}
G.Object7=Nana.Object=Object7;
var objProto=Object.prototype;
function objMemberEnumerable(name,flag){
flag=flag||0;
if(flag&1){
if(!this.propertyIsEnumerable(name))
return false;
}
if(flag&0x10){
if(name in this.constructor.prototype)
return false;
}
if(flag&0x100){
if(typeof this[name]=="function")
return false;
}
return true;
}
objProto.$canEnum=objProto.memberIsEnumerable=objMemberEnumerable;
function objAllPass(func,full){
var result=true,tmp;
for(var i in this){
if(this.memberIsEnumerable(i)){
tmp=func(i);
if(!tmp){
if(full)
result=tmp
else
return tmp;
}
}
}
return result;
}
function objAnyPass(func,full){
var result=false,tmp;
for(var i in this){
if(this.memberIsEnumerable(i)){
tmp=func(i);
if(tmp){
if(full)
result=tmp
else
return tmp;
}
}
}
return result;
}
objProto.$all=objProto.allMemberPass=objAllPass;
objProto.$any=objProto.anyMemberPass=objAnyPass;
function objFastSetup(src){
src.anyPass(function(i){
this[i]=src[i];
});
}
objProto.$combine=objProto.overwriteBy=objFastSetup;
function scFunc(object,funcName){
var f=object[funcName];
if(typeof(f)=="function"){
return function(){
return f.apply(object,arguments);
};
}else{
return f;
}
}
function scApply(func){
return function(object,args){
return func.apply(object,args);
};
}
function scCall(func){
return function(object){
var a=[];
for(var i=1;i<arguments.length;i++)
a.push(arguments[i]);
return func.apply(object,a);
};
}
Function.shortcutFunc=scFunc;
Function.shortcutApply=scApply;
Function.shortcutCall=scCall;
var mbLine="\r\n",mbSptr=","+mbLine;
Object.prototype.toExpr=function obj2expr(){
var array=[],n;
for(n in this){
this.propertyIsEnumerable(n)&&array.push(n.toExpr()+": "+Object.getExpr(this[n]));
}
return"{"+mbLine+array.join(mbSptr)+mbLine+"}";
};
Object.getExpr=function getExpr(o){
return o==null?o===null?"null":"void(0)":o.toExpr();
};
Boolean.prototype.toExpr=Number.prototype.toExpr=function num2expr(){
return""+this;
};
Date.prototype.toExpr=function date2expr(){
return"new Date("+this.valueOf()+")";
};
RegExp.prototype.toExpr=function rx2expr(){
return this.toString();
};
Array.prototype.toExpr=function arr2expr(){
var array=[],i;
for(i=0;i<this.length;i++){
array.push(Object.getExpr(this[i]));
}
return"["+mbLine+array.join(mbSptr)+mbLine+"]";
};
var rxSSE=/[\000\r\n"\\\u2028\u2029]/g;
var repSSE={
0:"000",
10:"n",
13:"r",
34:"\"",
92:"\\",
8232:"u2028",
8233:"u2029"
};
function ssFilter(match,index,whole){
return"\\"+repSSE[match.charCodeAt(0)];
}
function ssEscape(str){
return str.replace(rxSSE,ssFilter);
}
String.prototype.toExpr=function str2expr(){
return'"'+ssEscape(this)+'"';
};
this.$nanaInitialized&&this.$nanaInitialized();
}();
